package com.ziyun.erp.web.modules.production.controller;

import com.ziyun.erp.modules.order.vo.OrderItemVo;
import com.ziyun.erp.modules.production.dto.OrderItemSendPicsDto;
import com.ziyun.erp.modules.production.dto.ProcurementItemUpdateDto;
import com.ziyun.erp.modules.production.entity.ErpOrderItemEntity;
import com.ziyun.erp.modules.production.entity.vo.ErpOrderItemAllotVo;
import com.ziyun.erp.modules.production.service.ErpOrderItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * erp订单商品表
 *
 * @author guizhao
 * @email ...
 * @date 2018-08-22 14:44:58
 */
@RestController
@RequestMapping("production/erporderitem")
public class ErpOrderItemController {
    @Autowired
    private ErpOrderItemService erpOrderItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("production:erporderitem:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = erpOrderItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{eoItemId}")
    @RequiresPermissions("production:erporderitem:info")
    public R info(@PathVariable("eoItemId") Integer eoItemId){
        ErpOrderItemEntity erpOrderItem = erpOrderItemService.selectById(eoItemId);

        return R.ok().put("erpOrderItem", erpOrderItem);
    }


    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("production:erporderitem:update")
    public R update(@RequestBody ErpOrderItemEntity erpOrderItem){
        ValidatorUtils.validateEntity(erpOrderItem);
        erpOrderItemService.updateAllColumnById(erpOrderItem);//全部更新
        
        return R.ok();
    }

    /**
     * 获取erp订单审核明细信息
     */
    @RequestMapping("/itemAllotVos/{orderNo}")
    public R itemVos(@PathVariable("orderNo") String orderNo){
        List<ErpOrderItemAllotVo> erpOrderItemAllotVos = erpOrderItemService.selectErpOrderItemAllotVosByNo(orderNo);

        return R.ok().put("erpOrderItemAllotVos", erpOrderItemAllotVos);
    }

    /**
     * 保存订单商品发货图片
     * @param orderItemSendPicsDto
     * @return
     */
    @RequestMapping("/saveOrderItemSendPics")
    public R saveOrderItemSendPics(@RequestBody OrderItemSendPicsDto orderItemSendPicsDto){
        return erpOrderItemService.sendPics(orderItemSendPicsDto);
    }

    /**
     * 企业集采商品修改
     * @return
     */
    @RequestMapping("/procurementItemUpdate")
    public R procurementItemUpdate(@RequestBody ProcurementItemUpdateDto procurementItemUpdateDto){
        return erpOrderItemService.procurementItemUpdate(procurementItemUpdateDto);
    }

    /**
     * 查询被分配报价商品信息
     */
    @RequestMapping("/getAllotQuoteItem/{productionId}")
    public R getAllotQuoteItem(@PathVariable("productionId") Integer productionId){
        OrderItemVo orderItem = erpOrderItemService.getAllotQuoteItem(productionId);

        return R.ok().put("orderItem", orderItem);
    }

}
